package net.tv90.volunteerserveradmin.dao;

import io.lettuce.core.dynamic.annotation.Param;
import net.tv90.volunteerserveradmin.model.domain.Teacher;
import net.tv90.volunteerserveradmin.model.domain.User;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {

    User findByUsername(String username);

    User findByEmail(String email);

    boolean existsByUsername(String username);

    boolean existsByEmail(String email);

    User findUserByUsernameAndPassword(String username, String password);

    User findUserByUsernameOrEmail(String username, String email);

    User findUserByUsername(String username);

    List<User> findByUsernameContaining(String username);

    @Query("SELECT CASE WHEN u.role = 3 THEN true ELSE false END FROM User u WHERE u.id = :id")
    boolean isAdmin(@Param("id") Long id);

    User findUserByEmailAndPassword(String email, String password);
}